package com.lemon.smartsafety.ui.fragment.safe.data;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.ldzs.recyclerlibrary.view.FullyGridLayoutManager;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.entity.safe.company.FloorNumItem;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.activity.safe.data.BuildingCheckItemPositionActivity;
import com.lemon.smartsafety.ui.adapter.safe.data.BuildingFloorAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BaseFragment;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.smartsafety.utils.common.ViewUtils;

import java.util.List;

import butterknife.Bind;

/**
 * Created by Cooliean on 16/3/27.
 * 楼层
 */
public class BuildingFloorFragment extends BaseFragment implements RecyclerTClickListener<FloorNumItem>{
    private LoggerHelper loggerHelper = new LoggerHelper(BuildingFloorFragment.class);
    private List<FloorNumItem> floorNumItems;

    private int columnNumbers = 4;
    /** 是否是安全巡查界面过来的 */
    private boolean isSafeInspection = false;

    public static BuildingFloorFragment newInstance() {
        BuildingFloorFragment fragment = new BuildingFloorFragment();
        return fragment;
    }

    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private BuildingFloorAdapter mFloorAdapter;


    @Override
    protected void getBaseArguments() {
        if (getArguments() != null) {
            floorNumItems = (List<FloorNumItem>) getArguments().getSerializable(BundleKey.COMPANY_BUILDING_FLOOR_NUMBERS);
            isSafeInspection = getArguments().getBoolean(BundleKey.IS_SAFE_INSPECTION,false);
        }
        int screenWidth = ViewUtils.getScreenWidth(IApplication.context());
        int itemHeight = ViewUtils.dip2px(IApplication.context(), 48);
        columnNumbers = screenWidth / itemHeight;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.view_recycler_view;
    }

    @Override
    protected void initViews() {
        FullyGridLayoutManager gridLayoutManager = new FullyGridLayoutManager(getContext(), columnNumbers);
        gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
        gridLayoutManager.setSmoothScrollbarEnabled(true);
        mRecyclerView.setLayoutManager(gridLayoutManager);
        mRecyclerView.setNestedScrollingEnabled(false);
        mFloorAdapter = new BuildingFloorAdapter(floorNumItems, this, isSafeInspection);
        mRecyclerView.setAdapter(mFloorAdapter);
    }

    @Override
    public void onItemClick(FloorNumItem data, int position) {
//        FloorNumItemEvent event = new FloorNumItemEvent();
//        event.setTag(FloorNumItemEvent.class.getName());
//        event.setPosition(position);
//        event.setData(data);
//        AppService.getBus().post(event);

        ((BuildingCheckItemPositionActivity) getActivity()).getNetData(data.getItemTitle());
    }



}
